package com.tgy.leetcode;

/**
 *
 *  https://leetcode-cn.com/problems/toeplitz-matrix/
 */
public class _766_托普利茨矩阵 {

    public static boolean isToeplitzMatrix(int[][] matrix) {

        int row = matrix.length;
        int col = matrix[0].length;
        int x, y;
        for (int i = 0; i < col; i++) {

            int val = matrix[0][i];
            x = i;
            y = 0;
            while (true) {

                x++;
                y++;
                if (x >= col || y >= row) {

                    break;
                }

                if (matrix[y][x] != val) {

                    return false;
                }
            }
        }

        for (int i = 1; i < row; i++) {

            int val = matrix[i][0];
            x = 0;
            y = i;
            while (true) {

                x++;
                y++;
                if (x >= col || y >= row) {

                    break;
                }

                if (matrix[y][x] != val) {

                    return false;
                }
            }
        }

        return true;
    }

    public static void main(String[] args) {

        int[][] nums = {
                        {1,2,3,4},
                        {5,1,2,3},
                        {9,5,1,2}
                    };
        System.out.println(isToeplitzMatrix(nums));
    }
}
